"""
镜像管理
"""
from mcp.server import FastMCP
from pydantic import Field
from .base import docker_to_dict
import docker


def add_image_tools(mcp: FastMCP, _docker: docker.DockerClient):

    @mcp.tool()
    async def list_python_images(
            name: str = Field(default="python-sandbox", description="容器名称.")
    ):
        """列出python镜像"""
        images = _docker.images.list(name=name)
        result = [docker_to_dict(img) for img in images]
        return result

    @mcp.tool()
    async def remove_python_image(
            image: str = Field(..., description="镜像id或镜像名称."),
            force: bool = Field(False, description="是否强制删除镜像."),
    ):
        """删除python镜像"""
        _docker.images.remove(image=image, force=force)
        result = {"status": "removed", "image": image}
        return result
